// pages/property1/record/record.js
const app = getApp()	
Page({

    /**
     * 页面的初始数据
     */
    data: {
        array: ['2020', '2021', '2022'],
        default: '2022',
        token: '',
        houseId: 1,
        record:[],
        record1:[
            {
                price:6000.00,
                num:3,
                wuye:5000.00,
                gonggong:1000.00,
                date:'2020.3.1 19:34:56',
                by:'微信支付'
            },
            {
                price:6000.00,
                num:3,
                wuye:5000.00,
                gonggong:1000.00,
                date:'2020.3.1 19:34:56',
                by:'微信支付'
            },
            {
                price:6000.00,
                num:3,
                wuye:5000.00,
                gonggong:1000.00,
                date:'2020.3.1 19:34:56',
                by:'微信支付'
            }


        ]

    },
    bindPickerChange: function(e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        let index = e.detail.value
        let array = this.data.array
        this.setData({
          index,
          default: array[index]
        })

        var that = this;
        that.data.token = app.getToken()
        console.log(that.data.token)
        var houseId = that.data.houseId;
        var d = that.data.default;
        //网络请求获取账单数据
        wx.request({
          url: 'http://localhost:8080/community/pay/record?houseId='+houseId+'&&year='+d,
          method:'GET',
          header:{
            'content-type': 'application/json',
            'Authorization':  that.data.token
          },
          success:function(res){
            // console.log("userInfo" + JSON.stringify(res))
            console.log(res.data)
            that.setData({
              record: res.data.data
            })
          }
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
      that.data.token = app.getToken();
      console.log(that.data.token);
      var timestamp = Date.parse(new Date());
	    var date = new Date(timestamp);
	    //获取年份  
      var Y =date.getFullYear();
      var list = [];
      var i = 0;
      for(i=0;i<3;i++){
        list.push(Y-i);
      }
      //网络请求获取账单数据
      wx.request({
        url: 'http://localhost:8080/community/pay/record?houseId='+options.houseId+'&&year='+Y,
        method:'GET',
        header:{
          'content-type': 'application/json',
          'Authorization':  that.data.token
        },
        success:function(res){
          // console.log("userInfo" + JSON.stringify(res))
          console.log(res.data)
          that.setData({
            record: res.data.data,
            houseId: options.houseId,
            default: Y,
            array: list
          })
        }
      })

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})